# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
    def editable_content(options)
       options[:content] = { :element => 'span' }.merge(options[:content])
       options[:url] = {}.merge(options[:url])
       options[:ajax] = { :okText => "'Save'", :cancelText => "'Cancel'"}.merge(options[:ajax] || {})
       script = Array.new
       script << "new Ajax.InPlaceEditor("
       script << "  '#{options[:content][:options][:id]}',"
       script << "  '#{url_for(options[:url])}',"
       script << "  {"
       script << options[:ajax].map{ |key, value| "#{key.to_s}: #{value}" }.join(", ")
       script << "  }"
       script << ")"

       content_tag(
         options[:content][:element],
         options[:content][:text],
         options[:content][:options]
       ) + javascript_tag( script.join("\n") )
    end

    def pagination_links_remote(paginator, options={})
        update = options.delete(:update)
        with_form = options.delete(:with_form)
        with_form = with_form!=nil ? "parameters:Form.serialize($('" + with_form + "'))," : "" 
        str = pagination_links(paginator, options)
        if str != nil
              str.gsub(/href="([^"]*)"/) do
                url = $1
                "href=\"#\" onclick=\"new Ajax.Updater('" + update + "', '" + url +
                "', {" + with_form + "asynchronous:true, evalScripts:true}); return false;\""
              end
        end
    end
end
